﻿//----------------------------------------------------------------
//CodeArt.
//
//文件描述:
//
//创 建 人: dreamnan@hotmail.com(Blog:http://www.cnblogs.com/dreamnan)
//创建日期: 2010-7-15
//
//修订记录: 
//
//----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace CodeArt.SharePoint.CamlQuery
{
    using Microsoft.SharePoint;

    /// <summary>
    /// QuerySchema
    /// </summary>
    public abstract class QuerySchema
    {
        QuerySchema()
        { }

        /// <summary>
        /// SchemaName
        /// </summary>
        public abstract string SchemaName { get; }

        /// <summary>
        /// UserID
        /// </summary>
        public class UserID : QuerySchema
        {
            /// <summary>
            /// SCHEMA_NAME
            /// </summary>
            public const string SCHEMA_NAME = "{Me}";

            /// <summary>
            /// SchemaName
            /// </summary>
            public override string SchemaName
            {
                get
                { return SCHEMA_NAME; }
            }
            /// <summary>
            /// ToString
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
               return @"<UserID/>";
            }

        }

        /// <summary>
        /// Today
        /// </summary>
        public class Today : QuerySchema
        {
            const string Today_format = "<Today OffsetDays=\"{0}\" />";
            private int _offsetDays = 0;

            /// <summary>
            /// SCHEMA_NAME
            /// </summary>
            public const string SCHEMA_NAME = "{Today}";

            /// <summary>
            /// SchemaName
            /// </summary>
            public override string SchemaName
            {
                get
                { return SCHEMA_NAME; }
            }
            /// <summary>
            /// Today
            /// </summary>
            public Today()
            { 
            
            }

            /// <summary>
            /// Today
            /// </summary>
            /// <param name="days"></param>
            public Today(int days)
            {
                this.AddDays(days);
            }

            /// <summary>
            /// OffsetDays
            /// </summary>
            public int OffsetDays
            {
                get { return _offsetDays; }
                set { _offsetDays = value; }
            }

            /// <summary>
            /// AddDays
            /// </summary>
            /// <param name="days"></param>
            public void AddDays(int days)
            {
                _offsetDays = _offsetDays + days;
            }

            /// <summary>
            /// ToString
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                if (_offsetDays != 0)
                    return string.Format(Today_format, _offsetDays);
                else
                    return @"<Today/>";
            }

            /// <summary>
            /// +
            /// </summary>
            /// <param name="q"></param>
            /// <param name="iValue"></param>
            /// <returns></returns>
            public static Today operator +(Today q, int iValue)
            {
                q.AddDays(iValue);
                return q;
            }

            /// <summary>
            /// -
            /// </summary>
            /// <param name="q"></param>
            /// <param name="iValue"></param>
            /// <returns></returns>
            public static Today operator -(Today q, int iValue)
            {
                q.AddDays(-iValue);
                return q;
            }
        }
    }
}
